package com.niiwoo.civet.trade.report.upload.util;

import com.niiwoo.civet.trade.report.upload.exception.HashException;

import java.security.MessageDigest;
import java.io.InputStream;
import java.io.FileInputStream;


/**
 * 
 * @author wanglei02
 *
 */
public class HashUtil {

	public byte[] BJS_HashFile(String sFilePath)  throws HashException {
		try
		{
			MessageDigest md = MessageDigest.getInstance("SHA1");
			
			InputStream in = new FileInputStream(sFilePath);
			int blockSize = 131072;
			byte[] inBytes = new byte[blockSize];
			while (true)
			{
				int len = in.read(inBytes);
				if (len == -1) {
				break;
			}
				md.update(inBytes, 0, len);
			}
			
			byte[] hashValue = md.digest();
			
			in.close();
			return hashValue;
		}
		catch (Exception e) {
			//errorlog("Exception in hash,hash file", e);
			//debuglog("Exception in hash,hash file");
		}
		return null;
	}
}